$(function(){
	$("#LineName").combobox({
		url:"getLinesByOrg",
		valueField:'iLineID',
    	textField:'cLineName',
	});
	$('#dg').datagrid({
		url:"getGroupsByOrg",
		collapsible:true,
		fit:true,
		fitColumns:true,
		toolbar:'#footer',
		pagination:true,
		pageSize:20,
		pageList:[20,50,100,200],
		remoteSort:false,
		onLoadSuccess:function(data){
			if (data.total == 0) {
			$(this).datagrid('appendRow', { cLineName: '<div style="text-align:center;color:red">没有相关记录！</div>' }).datagrid('mergeCells', { index: 0, field: 'cLineName', colspan: 7 }) 
			$(this).closest('div.datagrid-wrap').find('div.datagrid-pager').hide();
			 $(this).datagrid('hideColumn', 'ck');
			} 
			else {
				$(this).closest('div.datagrid-wrap').find('div.datagrid-pager').show();
				$(this).datagrid('showColumn', 'ck');}
		},
		   columns:[[
			{field:'ck',checkbox:true},
			{field:'iPlanID',hidden:'true'},
			{field:'iLineID',hidden:'true'},
			{field:'cLineName',title:'线路名称',align:'center',width:'20%',
			 formatter:function(value,row,index){
				if(row.iLineID == undefined)return row.cLineName;
				return'<a href="linebaseinfo?LineID='+row.iLineID+'">'+row.cLineName+'</a>'
			}},
			{field:'cDate',title:'日期',align:'center',width:'15%'},
			{field:'cGuideName',title:'导游',align:'center',width:'15%'},
			{field:'cGuideTel',title:'电话',align:'center',width:'18%'},
			{field:'cCustomNum',title:'计划人数',align:'center',width:'10%'},
			{field:'cTypeName',title:'车型',align:'center',width:'10%'},
			{field:'iSeatNum',title:'座位数',align:'center',width:'10%'}
		]]
	});	
});

/* 新建 */
function selectLine(){
	var iLineID = $("#LineName").val();
	if(iLineID == "")alert("请先选择线路!");
	else{
		var url = "linegroup?iLineID=" + iLineID;
		location.href = url;
	}
}

/* 通知 */
function notice(){
	var rows = $('#dg').datagrid('getSelections');
	var checkNum = rows.length;
	if(checkNum==0){
		$.messager.alert('错误','至少选择一项','error');
	 } else if(checkNum>1){
		$.messager.alert('错误','最多选择一项','error');
	 }else{
		var id = rows[0].iPlanID;
		var line = rows[0].iLineID;
		var date = rows[0].cDate;
		var url = "GroupNotice?iPlanID=" + id + "&iLineID=" + line + "&cDate=" + date 
		location.href = url;
	 }
}

/* 结账 */
function check(){
	var rows = $('#dg').datagrid('getSelections');
	var checkNum = rows.length;
	if(checkNum==0){
		$.messager.alert('错误','至少选择一项','error');
	 } else if(checkNum>1){
		$.messager.alert('错误','最多选择一项','error');
	 }else{
		var id = rows[0].iPlanID;
		var url = "GroupCheck?iPlanID=" + id;
		location.href = url; 
	 }
}

